﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SD.Database;
using DataAccess;

namespace SDGUI
{
    public partial class LoginPage : UserControl
    {
        public LoginPage()
        {
            InitializeComponent();
            Player.AuthorizeUserCompleted += new Player.AuthorizeUserDelegate(Player_AuthorizeUserCompleted);
        }

        void Player_AuthorizeUserCompleted(AuthorizeEventArgs e)
        {
            if (e.Authorized == true)
            {
                WrongPasswordBox.Text = "Success";
            }
            else
            {
                WrongPasswordBox.Text = "Wrong username or password!";
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            WrongPasswordBox.Text = "Trying to authorize";
            Player.BeginAuthorizeUser(UserBoxTxt.Text, PasswordBoxTxt.Password);
            //if (UserFunctions.AuthorizeUser(UserBoxTxt.Text, PasswordBoxTxt.Password) == true)
            //{
            //    WrongPasswordBox.Text = string.Empty;
            //    //use http://silverlight.net/forums/p/16218/54319.aspx trick to switch xaml page
            //    Application.Current.Resources.Add("Login", UserBoxTxt.Text);

            //    Grid g = Application.Current.RootVisual as Grid;  // Find the root grid
            //    g.Children.RemoveAt(0);  // Remove old page control
            //    g.Children.Add(new Page()); // Add new page control 
            //}
            //else
            //{
            //    WrongPasswordBox.Text = "Incorrect user name or password!";
            //}
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Grid g = Application.Current.RootVisual as Grid;  // Find the root grid
            g.Children.RemoveAt(0);  // Remove old page control
            g.Children.Add(new RegisterControl()); // Add new page control 
        }
    }
}
